package com.mingmen.canting.gongyingshang;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.mingmen.canting.R;
import com.mingmen.canting.defineview.GlideRoundTransform;
import com.mingmen.canting.httpconfig.AppConfig;
import com.mingmen.canting.model.ShopListModel;
import com.mingmen.canting.model.ShopRightDetailModel;

import java.util.List;


public class GongYingRightAdapter extends RecyclerView.Adapter<GongYingRightAdapter.ViewHolder> {
    List<ShopRightDetailModel.CommodiousBean> myLiveList;
    Context mContext;
    private OnItemClickListener mOnItemClickListener;


    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClickListener(View view, int pos, List<ShopRightDetailModel.CommodiousBean> myLiveList);
    }


    public GongYingRightAdapter(Context context, List<ShopRightDetailModel.CommodiousBean> list) {
        this.mContext = context;
        this.myLiveList = list;

    }

    public void setDataList(List<ShopRightDetailModel.CommodiousBean> list) {
        myLiveList = list;

        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_gongyingright, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    int mycount = 0;

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        ShopRightDetailModel.CommodiousBean myLive = myLiveList.get(holder.getAdapterPosition());


        holder.mTvTitle.setText("名称: " + myLive.getCommodityName());

//        Glide.with(mContext).load("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1596014050715&di=6a1ac18ffe1c13bd0957c1073c477cd7&imgtype=0&src=http%3A%2F%2Fimg.pconline.com.cn%2Fimages%2Fphotoblog%2F8%2F0%2F6%2F5%2F8065746%2F20091%2F6%2F1231206650604.jpg").into(holder.ivAvatar);
        Glide.with(mContext).load(AppConfig.IMGURL + myLive.getPicture()).dontAnimate().placeholder(R.mipmap.zhanwei).error(R.mipmap.zhanwei).transform(new GlideRoundTransform(mContext, 5)).into(holder.ivAvatar);
        if (myLive.getIsDefault().equals("0")) {
            holder.checkbox_moren.setChecked(false);
        } else if (myLive.getIsDefault().equals("1")) {
            holder.checkbox_moren.setChecked(true);
        } else if (myLive.getIsDefault().equals("2")) {
            holder.checkbox_moren.setChecked(false);
        }

        holder.checkbox_moren.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickListener.onItemClickListener(v, position, myLiveList);
            }
        });

    }

    @Override
    public int getItemCount() {
        return myLiveList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {


        TextView mTvTitle;

        ImageView ivAvatar;

        LinearLayout content;


        LinearLayout layout_produce;


        LinearLayout layout_guige;
        CheckBox checkbox_moren;


        public ViewHolder(View itemView) {
            super(itemView);

            mTvTitle = (TextView) itemView.findViewById(R.id.tvCity);
            ivAvatar = (ImageView) itemView.findViewById(R.id.ivAvatar);

            content = (LinearLayout) itemView.findViewById(R.id.content);


            layout_produce = itemView.findViewById(R.id.layout_produce);

            layout_guige = itemView.findViewById(R.id.layout_guige);
            checkbox_moren = itemView.findViewById(R.id.checkbox_moren);
        }
    }


}
